<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <meta name="description" content="" />
    <meta name="author" content="" />
    <title>选课界面</title>
    <link href="/css/bootstrap.min.css" rel="stylesheet" />
</head>
<style>
    body{
        background: linear-gradient(90deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.2) 100%), url("/img/bg-2.jpg");
        background-position: center center;
        background-repeat: no-repeat;
        background-size: cover;
    }

</style>
<body>
<div class="container">
    <div style="margin-top: 100px" class="row">
        <div class="span3">
        </div>
        <div class="span6">
            <div class="form-group">
                <table style="text-align: center" class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>
                            学号
                        </th>
                        <th>
                            姓名
                        </th>
                        <th>
                            课程
                        </th>
                        <th>
                            学分
                        </th>
                        <th>
                            操作
                        </th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td>1925122013</td>
                        <td>黄臻良</td>
                        <td>高数上</td>
                        <td>5</td>
                        <td><input type="checkbox" class="check"></td>
                    </tr>
                    <tr>
                        <td>1925122013</td>
                        <td>黄臻良</td>
                        <td>高数下</td>
                        <td>5</td>
                        <td><input type="checkbox" class="check"></td>
                    </tr>
                    <tr>
                        <td>1925122013</td>
                        <td>黄臻良</td>
                        <td>线性代数</td>
                        <td>4</td>
                        <td><input type="checkbox" class="check"></td>
                    </tr>
                    <tr>
                        <td>1925122013</td>
                        <td>黄臻良</td>
                        <td>离散数学</td>
                        <td>4</td>
                        <td><input type="checkbox" class="check"></td>
                    </tr>
                    <tr>
                        <td>1925122013</td>
                        <td>黄臻良</td>
                        <td>操作系统</td>
                        <td>3</td>
                        <td><input type="checkbox" class="check"></td>
                    </tr>
                    <tr>
                        <td>1925122013</td>
                        <td>黄臻良</td>
                        <td>计算机组成原理</td>
                        <td>3</td>
                        <td><input type="checkbox" class="check"></td>
                    </tr>
                    <tr>
                        <td>1925122013</td>
                        <td>黄臻良</td>
                        <td>计算机网络</td>
                        <td>3</td>
                        <td><input type="checkbox" class="check"></td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div style="text-align: center">
            <a class="btn btn-primary" onclick="checksubmit()" >确认</a>
        </div>


        <div class="span3">
        </div>
    </div>
</div>


<script>


    function checksubmit() {
        var formData = new FormData();
        var courseName = [];
        $("input[type='checkbox']:checked").each(function () {
            console.log($(this).parent().parent().find('td').eq(2).text()+ '---------------');
            var coursename = $(this).parent().parent().find('td').eq(2).text();
            var credit = $(this).parent().parent().find('td').eq(3).text();
            courseName.push(coursename);
            formData.append('courseName', coursename);
            formData.append('credit', credit);
        })
        if (courseName.length==0){
            alert("请选择课程");
            return;
        }
        $.ajax({
            url: "/student/selected",
            type: 'post',
            cache: false,
            data: formData,
            processData: false,
            contentType: false,
            success: function (result) {
               // console.log(result);
                document.write(result);
            },
            error : function (result) {
               // console.log(result);
                alert("请重试.");
            }
         });
    }
</script>

<script src="/js/bootstrap.min.js"></script>
<script src="/js/jquery-1.11.1.min.js"></script>
</body>
</html>